package com.newlink.building.common_base.event

import com.smart.rinoiot.device_sdk.bean.device.AgoraRtcTokenVO
import com.smart.rinoiot.device_sdk.bean.device.AgoraRtmTokenVO
import com.squareup.moshi.Json
import com.newlink.building.common_base.model.bean.OpenDoorKcpResult
import java.io.Serializable
import java.text.SimpleDateFormat

/**
 * @Author: Jake
 * @Date: 2022/10/10
 * @Description:
 */
interface BaseActionBean : Serializable

open class BaseApiVersionBean(val version: String = MQTT_API_VERSION) : BaseActionBean

const val OPEN_DOOR_SUCCESS = 1
const val OPEN_DOOR_FAILED = 0
const val MQTT_API_VERSION: String = "1.0.0"

data class OpenDoorKcpActionEvent(
    var result: OpenDoorKcpResult
)

data class CallCreateActionBean(
    val channelName: String = "",
    val aid: Int = 0,
    val msgId: String = "app_${System.currentTimeMillis()}",
    val rawData: String = "",
) : BaseApiVersionBean(), Serializable


data class CallSipBean(
    var callId: String = "",
    var sipType: Int = 0,
    var channelName: String = "",
    val msgId: String = "app_${System.currentTimeMillis()}",
    val from: String,
    val to: String,
    var aid: Int = 0,
    var sipBody: String
) : BaseApiVersionBean(), Serializable

data class CallMessageBean(
    val msgType: String = "",
    val currentTime: String = "",
    val msgId: String = "app_${System.currentTimeMillis()}",
    val data: CallMessageDataBean?,
) : BaseApiVersionBean(), Serializable

data class CallMessageDataBean(
    val channelName: String = "",
    val from: String,
    val to: String,
    val sipNumber: String?,
    val callId: String = ""
)

data class OpenDoorActionBean(
    val currentTime: String,
    val `data`: Data,
    val msgType: String,
    val msgId: String
) : BaseApiVersionBean(), Serializable {
    data class Data(
        val doors: List<Door>,
        val mac: String
    ) : Serializable {
        data class Door(
            val action: Int,
            val index: Int
        ) : Serializable
    }
}

data class OpenDoorActionResponseBean(
    val currentTime: String,
    val `data`: DataRes,
    val msgType: String,
    val version: String,
    val msgId: String
) {
    data class DataRes(
        val doors: List<DoorRes>
    ) {
        data class DoorRes(
            val index: Int,
            val reason: String,
            val result: Int
        )
    }
}

class OpenDoorResultBean(
    var msgId: String,
    var which: Int,
    var success: Boolean,
    var reason: String
)

data class MqttResponseBean<T>(
    val currentTime: String,
    val `data`: T,
    val msgType: String,
    val version: String,
    val msgId: String,
    val code: Int
)

data class CallLogBean(
    val msgType: String = "call_logs_up",
    val currentTime: String = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(System.currentTimeMillis()),
    val msgId: String = "app_${System.currentTimeMillis()}",
    val data: Data,
) : BaseApiVersionBean(), Serializable {
    data class Data(
        val callerNumber: String,
        val answerNumber: String,
        val startStamp: String,
        val duration: String,
        val hangupCause: String,
        val callType: Int
    ) : Serializable
}


//{
//   "msgId":"123456789",
//   "rtmToken": {
//      "account": "d_1234",
//      "rtmToken": "007eJxTYDjRLiEjd7bglczatrurLga31q+K1tDwsWHv1TESFFe041JgME1KMUhLtTAysjAzMDFLS0kyNbQwtDSwNDFIMk20ME8LFApIE+BjYDjgvGsGIwMTAyMQgvhsDCnxhkbGJgAg3BoR",
//      "expireSecond": 3600
//    },
//    "rtcToken": {
//      "channelName": "v_test1",
//      "uid": 1234,
//      "rtcToken": "007eJxTYFBQ7K/9JWIy/1vv8Yuf2uMNT/cmXZUT9+PZ+dRwWfVi9xYFBtOkFIO0VAsjIwszAxOztJQkU0MLQ0sDSxODJNNEC/O0QKGANAE+BoYnp+5eZGRgZGABYhCfCUwyg0kWMMnOUBZfklpcYsjCYGhkbAIAPOkhLQ==",
//      "expireSecond": 3600
//    }
//   "rawData":""
//}

data class CallCreateBean(
    @Json(name = "msgId") var msgId: String,
    @Json(name = "data") var data: TokenVo?,
    @Json(name = "rawData") var rawData: String
)

data class TokenVo(
    @Json(name = "rtmToken") var rtmToken: AgoraRtmTokenVO,
    @Json(name = "rtcToken") var rtcToken: AgoraRtcTokenVO,
)

data class RtmToken(
    @Json(name = "account") var account: String,
    @Json(name = "rtmToken") var rtmToken: String,
    @Json(name = "expireSecond") var expireSecond: Int
)

data class RtcToken(
    @Json(name = "channelName") var channelName: String,
    @Json(name = "uid") var uid: Int,
    @Json(name = "rtcToken") var rtcToken: String,
    @Json(name = "expireSecond") var expireSecond: Int
)
